import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/jsx-runtime.js";
import node from "eslint-plugin-n";
import eslintPluginUnicorn from "eslint-plugin-unicorn";

export default [
  /* 脚本代码 */
  ...[
    pluginJs.configs.recommended,
    ...tseslint.configs.strictTypeChecked,
    ...tseslint.configs.stylisticTypeChecked,
    pluginReactConfig,
    eslintPluginUnicorn.configs["flat/recommended"],
  ].map((conf) => ({
    ...conf,
    languageOptions: {
      globals: globals.browser,
      parser: tseslint.parser,
      parserOptions: {
        project: true,
        tsconfigRootDir: import.meta.dirname,
        ecmaFeatures: { jsx: true },
      },
    },
    plugins: {
      "@typescript-eslint": tseslint.plugin,
      unicorn: eslintPluginUnicorn,
    },
    settings: {
      ...conf.settings,
    },
    rules: {
      ...conf.rules,
      "@typescript-eslint/no-dynamic-delete": "off",
      "@typescript-eslint/no-unused-expressions": "off",
      "@typescript-eslint/no-deprecated": "off",
      "@typescript-eslint/no-unnecessary-condition": "off",
      "@typescript-eslint/no-unsafe-assignment": "off",
      "@typescript-eslint/no-unsafe-member-access": "off",
      "@typescript-eslint/no-unsafe-argument": "off",
      "@typescript-eslint/no-unsafe-call": "off",
      "@typescript-eslint/no-unsafe-return": "off",
      "@typescript-eslint/no-redundant-type-constituents": "off",
      "@typescript-eslint/no-confusing-void-expression": "off",
      "@typescript-eslint/prefer-promise-reject-errors": "off",
      "@typescript-eslint/only-throw-error": "off",
      "@typescript-eslint/no-non-null-assertion": "off",
      "n/no-missing-import": "off",
      "unicorn/filename-case": "off",
      "unicorn/no-thenable": "off",
      "unicorn/no-null": "off",
      "unicorn/no-nested-ternary": "off",
    },
    files: ["**/*.mts", "**/*.tsx"],
  })),
  /* Node */
  ...[
    pluginJs.configs.recommended,
    node.configs["flat/recommended-script"],
    ...tseslint.configs.strictTypeChecked,
    ...tseslint.configs.stylisticTypeChecked,
    eslintPluginUnicorn.configs["flat/recommended"],
  ].map((conf) => ({
    ...conf,
    languageOptions: {
      globals: globals.node,
      parser: tseslint.parser,
      parserOptions: {
        project: true,
        tsconfigRootDir: import.meta.dirname,
        ecmaFeatures: { jsx: true },
      },
    },
    plugins: {
      n: node,
      "@typescript-eslint": tseslint.plugin,
      unicorn: eslintPluginUnicorn,
    },
    rules: {
      ...conf.rules,
      "@typescript-eslint/no-non-null-assertion": "off",
      "n/no-unpublished-require": "off",
      "n/no-unpublished-import": "off",
      "n/no-missing-import": "off",
      "unicorn/filename-case": "off",
    },
    files: ["**/*.ts"],
  })),
];
